/**
 * 劳务信息JS
 * @author Assassin
 */
/*$(document).ready(function(){
    $('#uploadPictureLink').on('click',function(){
        $('#pictureFile').click();
    });
    $('#pictureImg').on('click',function(){
        $('#pictureFile').click();
    });
});

// 上传缩略图片
function uploadPicture(){
    $.ajaxFileUpload({
        url:shiro.baseUrl + "uploadPicture",
        secureuri:false,
        fileElementId:"pictureFile",
        dataType: 'json',
        success: function (data) {
            $("#pictureImg").attr("src", data.preUrl + "?v=" + new Date());
            $('#picture').val(data.picture);
        },error:function(XMLHttpRequest, textStatus, errorThrown){
            layer.msg(errorThrown, {icon: 5,time: 1000});
        }
    });
}*/


// 执行添加劳务信息
function excuteAddLabour() {
    var labourName = $.trim($('#labourName').val());
    if(shiro.util.isEmpty(labourName)) {
        layer.tips('劳务名称不能为空', '#labourName');
        return false;
    }
    var companyName = $.trim($('#companyName').val());
    if(shiro.util.isEmpty(companyName)) {
    	layer.tips('公司名称不能为空', '#companyName');
    	return false;
    }
    var workAddress = $.trim($('#workAddress').val());
    if(shiro.util.isEmpty(workAddress)) {
    	layer.tips('工作地址不能为空', '#workAddress');
    	return false;
    }
    var labourDesc = CKEDITOR.instances.content_editor.getData();
    if(shiro.util.isEmpty(labourDesc)) {
        layer.msg('工作描述不能为空', {icon: 5,time: 1000});
        return false;
    }
    var labourEducation = $('#labourEducation').val();
    if(shiro.util.isEmpty(labourEducation)) {
    	 layer.tips('学历要求不能为空', '#labourEducation');
        return false;
    }
    var labourMinYear = $('#labourMinYear').val();
    if(shiro.util.isEmpty(labourEducation)) {
    	 layer.tips('最低年限不能为空', '#labourMinYear');
        return false;
    }
    var labourMaxYear = $('#labourMaxYear').val();
    if(shiro.util.isEmpty(labourMaxYear)) {
    	 layer.tips('最高年限不能为空', '#labourMaxYear');
        return false;
    }
    var labourMinPrice = $('#labourMinPrice').val();
    if(shiro.util.isEmpty(labourMinPrice)) {
    	 layer.tips('最低薪资不能为空', '#labourMinPrice');
        return false;
    }
    var labourMaxPrice = $('#labourMaxPrice').val();
    if(shiro.util.isEmpty(labourMaxPrice)) {
    	 layer.tips('最高薪资不能为空', '#labourMaxPrice');
        return false;
    }
    // 提交信息
    shiro.ajax({
        url: 'labour/executeAddLabour',
        data:{
        	'labourName': labourName, 
        	"companyName": companyName,
        	"labourDesc":labourDesc,
        	'labourEducation':labourEducation,
        	'workAddress':workAddress,
        	"labourMinYear":labourMinYear,
        	"labourMaxYear":labourMaxYear,
        	"labourMinPrice":labourMinPrice,
        	"labourMaxPrice":labourMaxPrice
        },
        success: function(data) {
            if(data.result == 0) {
                layer.msg(data.message, {icon: 1,time: 1000}, function() {
                    window.location.href = shiro.baseUrl + "labour/list";
                });
            } else {
                layer.msg(data.message, {icon: 5,time: 1000});
            }
        }
    });
    return false;
}

// 执行修改劳务信息
function excuteEditLabour() {
	var labourName = $.trim($('#labourName').val());
    if(shiro.util.isEmpty(labourName)) {
        layer.tips('劳务名称不能为空', '#labourName');
        return false;
    }
    var companyName = $.trim($('#companyName').val());
    if(shiro.util.isEmpty(companyName)) {
    	layer.tips('公司名称不能为空', '#companyName');
    	return false;
    }
    var workAddress = $.trim($('#workAddress').val());
    if(shiro.util.isEmpty(workAddress)) {
    	layer.tips('工作地址不能为空', '#workAddress');
    	return false;
    }
    var labourDesc = CKEDITOR.instances.content_editor.getData();
    if(shiro.util.isEmpty(labourDesc)) {
        layer.msg('工作描述不能为空', {icon: 5,time: 1000});
        return false;
    }
    var labourEducation = $('#labourEducation').val();
    if(shiro.util.isEmpty(labourEducation)) {
    	 layer.tips('学历要求不能为空', '#labourEducation');
        return false;
    }
    var labourMinYear = $('#labourMinYear').val();
    if(shiro.util.isEmpty(labourEducation)) {
    	 layer.tips('最低年限不能为空', '#labourMinYear');
        return false;
    }
    var labourMaxYear = $('#labourMaxYear').val();
    if(shiro.util.isEmpty(labourMaxYear)) {
    	 layer.tips('最高年限不能为空', '#labourMaxYear');
        return false;
    }
    var labourMinPrice = $('#labourMinPrice').val();
    if(shiro.util.isEmpty(labourMinPrice)) {
    	 layer.tips('最低薪资不能为空', '#labourMinPrice');
        return false;
    }
    var labourMaxPrice = $('#labourMaxPrice').val();
    if(shiro.util.isEmpty(labourMaxPrice)) {
    	 layer.tips('最高薪资不能为空', '#labourMaxPrice');
        return false;
    }
    var labourId = $('#labourId').val();
    // 提交信息
    shiro.ajax({
        url: 'labour/executeEditLabour',
        data:{
        	'labourId': labourId, 
        	'labourName': labourName, 
        	"companyName": companyName,
        	"labourDesc":labourDesc,
        	'labourEducation':labourEducation,
        	'workAddress':workAddress,
        	"labourMinYear":labourMinYear,
        	"labourMaxYear":labourMaxYear,
        	"labourMinPrice":labourMinPrice,
        	"labourMaxPrice":labourMaxPrice
        },
        success: function(data) {
            if(data.result == 0) {
                layer.msg(data.message, {icon: 1,time: 1000}, function() {
                    window.location.href = shiro.baseUrl + "labour/list";
                });
            } else {
                layer.msg(data.message, {icon: 5,time: 1000});
            }
        }
    });
    return false;
}

// 删除劳务
function deleteLabour(labourId) {
    layer.msg('确定删除该劳务？', {
        time: 0,
        btn: ['确定', '取消'],
        yes: function(index){
            layer.close(index);
            // 提交删除
            shiro.ajax({
                url: 'labour/delete',
                data:{"labourId": labourId},
                success: function(data) {
                    if(data.result == 0) {
                        layer.msg(data.message, {icon: 1,time: 1000}, function() {
                            window.location.href = shiro.baseUrl + "labour/list";
                        });
                    } else {
                        layer.msg(data.message, {icon: 5,time: 1000});
                    }
                }
            });
        }
    });
}

// 批量删除劳务
function batchDeleteLabour() {
    var labourIdArray = shiro.form.getCheckBoxSelectValues('labourIdCheckBox');
    if(labourIdArray.length == 0) {
        layer.msg('请选择要操作的数据行', {icon: 5,time: 1000});
    } else {
        layer.msg('确定删除选中的劳务？', {
            time: 0,
            btn: ['确定', '取消'],
            yes: function(index){
                layer.close(index);
                var labourIds = labourIdArray.join(',');
                // 提交删除
                shiro.ajax({
                    url: 'labour/batchDelete',
                    data:{"labourIds": labourIds},
                    success: function(data) {
                        if(data.result == 0) {
                            layer.msg(data.message, {icon: 1,time: 1000}, function() {
                                window.location.href = shiro.baseUrl + "labour/list";
                            });
                        } else {
                            layer.msg(data.message, {icon: 5,time: 1000});
                        }
                    }
                });
            }
        });
    }
}


//通过劳务
function adoptLabour(labourId) {
    layer.msg('确定通过该劳务？', {
        time: 0,
        btn: ['确定', '取消'],
        yes: function(index){
            layer.close(index);
            // 提交删除
            shiro.ajax({
                url: 'labour/adoptLabour',
                data:{"labourId": labourId},
                success: function(data) {
                    if(data.result == 0) {
                        layer.msg(data.message, {icon: 1,time: 1000}, function() {
                            window.location.href = shiro.baseUrl + "labour/listNo";
                        });
                    } else {
                        layer.msg(data.message, {icon: 5,time: 1000});
                    }
                }
            });
        }
    });
}


//驳回劳务
function rejectLabour(labourId) {
	layer.open({
		type: 2,
		area: ['400px', '230px'],
		title: '填写驳回原因',
		content: shiro.baseUrl + 'labour/rejectLabour?labourId='+labourId
	});
}

/**
 * 更新驳回原因
 */
function updateReason(){
	var labourId = $.trim($('#labourId').val());
	var reason = $.trim($('#reason').val());
	if(shiro.util.isEmpty(reason)) {
        layer.msg('驳回原因不能为空', {icon: 5,time: 1000});
        return false;
    }
	 // 提交信息
    shiro.ajax({
        url: 'labour/updateReason',
        data:{"labourId":labourId,"reason":reason},
        success: function(data) {
            if(data.result == 0) {
                layer.msg(data.message, {icon: 1,time: 1000}, function() {
                	parent.layer.closeAll();
                	parent.window.location.href = shiro.baseUrl + "labour/listNo";
                });
            } else {
                layer.msg(data.message, {icon: 5,time: 1000});
            }
        }
    });
    return false;
}


function viewLabour(labourId){
	layer.open({
		type: 2,
		area: ['400px', '230px'],
		title: '查看驳回原因',
		content: shiro.baseUrl + 'labour/viewLabour?labourId='+labourId
	});
}



